package cn.xopencode.appletweb.controller.record.roominrecord;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.recordservice.rpc.robotroom.vo.RobotRoomRecordEmpRelVO;
import cn.xopencode.recordservice.rpc.robotroom.vo.RobotRoomRecordUpdateVO;
import cn.xopencode.recordservice.rpc.roominrecord.RoomInRecordRpc;
import cn.xopencode.recordservice.rpc.roominrecord.dto.RoomInRecordCreateDTO;
import cn.xopencode.recordservice.rpc.roominrecord.dto.RoomInRecordPageDTO;
import cn.xopencode.recordservice.rpc.roominrecord.dto.RoomInRecordUpdateDTO;
import cn.xopencode.recordservice.rpc.roominrecord.vo.RoomInRecordEmpRelVO;
import cn.xopencode.recordservice.rpc.roominrecord.vo.RoomInRecordPageVO;
import cn.xopencode.recordservice.rpc.roominrecord.vo.RoomInRecordUpdateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Api(tags = "配电室进出记录 API")
@RestController
@RequestMapping("/roominrecord")
@Validated
public class RoomInRecordController {

    @DubboReference(version = "${dubbo.consumer.RoomInRecordRpc.version}")
    private RoomInRecordRpc roomInRecordRpc;
    /**
     * 根据查询条件 分页获取所有的配电室进出记录
     * @param pageDTO
     * @return
     */
    @PostMapping("/getAllByQuery")
    @ApiOperation("根据查询条件分页获取所有的配电室进出记录")
    public CommonResult<PageResult<RoomInRecordPageVO>> getPageRobotRoomRecord(RoomInRecordPageDTO pageDTO){
        PageResult<RoomInRecordPageVO> result = new PageResult<>();
        List<RoomInRecordPageVO> list = new ArrayList<>();

        RoomInRecordPageVO vo = new RoomInRecordPageVO();
        vo.setInDatetime(new Date());
        vo.setInEmpNum(2);
        vo.setEmpRels("张三、李四");
        list.add(vo);
        RoomInRecordPageVO vo2 = new RoomInRecordPageVO();
        vo.setInDatetime(new Date());
        vo.setInEmpNum(1);
        vo.setEmpRels("王一");
        list.add(vo2);

        result.setList(list);
        return CommonResult.success(result);
    }

    /**
     *  新增配电室出入记录
     * @param roomDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增配电室出入记录")
    public CommonResult<Integer> createRoomInRecord(@Valid RoomInRecordCreateDTO roomDTO){
        return CommonResult.success(1);
//        return roomInRecordRpc.createRoomInRecord(roomDTO);
    }

    /**
     *  更新配电室出入记录
     * @param roomDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("更新配电室出入记录")
    public CommonResult<Integer> updateRoomInRecord(@Valid RoomInRecordUpdateDTO roomDTO){
        return CommonResult.success(1);
//        return roomInRecordRpc.updateRoomInRecord(roomDTO);
    }


    /**
     * 根据id获取配电室进出记录详细
     * @param roomId
     * @return
     */
    @GetMapping("/getById")
    @ApiOperation("根据id获取配电室进出记录详细")
    public CommonResult<RoomInRecordUpdateVO> getRoomInRecordById(String roomId){
        RoomInRecordUpdateVO vo = new RoomInRecordUpdateVO();
        vo.setInDatetime(new Date());
        vo.setInEmpNum(2);
        vo.setInReason(1);
        vo.setOutDatetime(new Date());
        vo.setNonExpertName("李四");
        vo.setRoomId("111");


        List<RoomInRecordEmpRelVO> list = new ArrayList<RoomInRecordEmpRelVO>();
        RoomInRecordEmpRelVO relVO = new RoomInRecordEmpRelVO();
        relVO.setEmpId("001");
        relVO.setId("1");
        relVO.setRecordId("A111");

        RoomInRecordEmpRelVO relVO2 = new RoomInRecordEmpRelVO();
        relVO2.setEmpId("002");
        relVO2.setId("2");
        relVO2.setRecordId("A112");
        list.add(relVO);
        list.add(relVO2);

        vo.setEmpList(list);
        return CommonResult.success(vo);
    }
}
